package com.junyue.control.platform.utils;

import com.alibaba.fastjson.JSONArray;
import com.junyue.control.platform.PlatformApplication;
import com.junyue.control.platform.entity.ControlData;
import com.junyue.control.platform.entity.ResultData;
import com.junyue.control.platform.entity.VersionData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FileToData
{
    public static Map<String, ResultData> getMapData(String filePath)
    {
        Map<String, ResultData> dataMap = new HashMap();
        String data = ReadFileUtils.readFileByLines(filePath);
        if (data != null)
        {
            String replaceData = data.replaceAll("\t", "");
            List<ControlData> controlDataList = JSONArray.parseArray(replaceData, ControlData.class);
            for (ControlData controlData : controlDataList) {
                dataMap.put(controlData.getVersionName(), controlData.getResultData());
            }
            return dataMap;
        }
        return dataMap;
    }

    public static Map<String, ResultData> getVersionMapData(String filePath)
    {
        Map<String, ResultData> dataMap = new HashMap();
        String data = ReadFileUtils.readFileByLines(filePath);
        if (data != null)
        {
            String replaceData = data.replaceAll("\t", "");
            List<ControlData> controlDataList = JSONArray.parseArray(replaceData, ControlData.class);
            for (ControlData controlData : controlDataList) {
                dataMap.put(controlData.getResultData().getData().getVersionId(), controlData.getResultData());
            }
            return dataMap;
        }
        return dataMap;
    }

    public static List<ControlData> getListData(String filePath)
    {
        List<ControlData> controlDataList = new ArrayList();
        String data = ReadFileUtils.readFileByLines(filePath);
        if (data != null)
        {
            String replaceData = data.replaceAll("\t", "");
            controlDataList = JSONArray.parseArray(replaceData, ControlData.class);
            return controlDataList;
        }
        return controlDataList;
    }

    public static String getStringData(String filePath)
    {
        String data = ReadFileUtils.readFileByLines(filePath);
        if (data != null) {
            return data;
        }
        return "";
    }
}
